
Partial Class Pages_Controls_ctlFrmFichaFamiliar
    Inherits System.Web.UI.UserControl
    Dim bEnabled As Boolean = True
    Dim TitularID As Integer
    Dim FamiliarID As Integer

    Public Property Enabled() As Boolean
        Get
            Return bEnabled

        End Get
        Set(ByVal value As Boolean)
            bEnabled = value
            

        End Set
    End Property

    Protected Sub cmbParentesco_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If cmbParentesco.Value = 4 Then
            lblIngresoMensual.ClientVisible = True
            txtIngresoMensual.ClientVisible = True
        Else
            lblIngresoMensual.ClientVisible = False
            txtIngresoMensual.ClientVisible = False
        End If
    End Sub

    

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            TitularID = DBUtilities.TitularID
            If Not IsNothing(Request.QueryString("KEY")) Then
                Dim variable As String = "" & Request.QueryString("KEY").ToString()
                Dim form As String = "" & Request.QueryString("F").ToString() ' variables el codigo de familiar ID

                Session.Add("Formulario", form)

                If variable <> 0 Then
                    CargaDatosFamiliares(TitularID, variable)
                Else

                    NuevoDatosFamiliares()
                End If
            Else
                NuevoDatosFamiliares()
            End If
            EnabledControls()

        End If

    End Sub

    Private Sub CargaDatosFamiliares(ByVal TitularID As Integer, ByVal FamiliarID As Integer)
        Dim objPersona As New BusinessLogic.crFichaFamiliar
        Dim ds As BusinessEntity.CCFamiliar
        ds = objPersona.GetDatosFichaFamiliar(TitularID, FamiliarID)
        txtFamiliarID.Text = ds.TB_SOC_ESI_Familiar_ID
        txtTitularID.Text = ds.TB_SOC_ESI_Titular_ID
        txtPersonaID.Text = ds.TB_SOC_ESI_Persona_ID 'TB_SOC_ESI_Persona_ID
        cmbParentesco.Value = ds.TB_SOC_ESI_Parentesco_ID ' DESCRIPCION
        txtCodPersona.Text = ds.CodPersona
        txtNombres.Text = ds.Nombres
        txtApellidoPaterno.Text = ds.ApellidoPaterno
        txtApellidoMaterno.Text = ds.ApellidoMaterno
        cmbFechaNacimiento.Value = Convert.ToDateTime(ds.FechaNacimiento)
        'cmbFechaInscripcion.Text = ds.Fecha_Inscripcion
        If ds.TB_SOC_ESI_Parentesco_ID = 4 Then
            lblIngresoMensual.ClientVisible = True
            txtIngresoMensual.ClientVisible = True
        End If
        txtIngresoMensual.Value = ds.IngresoMensual

        cmbTipoDocumento.Value = ds.TipoDocumento
        txtNumeroDocumento.Text = ds.NroDocumento
        cmbSexo.Value = ds.Sexo
    End Sub

    'Protected Sub imgNuevo_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
    '    CargaDatosfamiliares(TitularID, FamiliarID)
    'End Sub

    Protected Sub btnGrabar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        GrabaFichaFamiliar()

    End Sub

    Sub NuevoDatosFamiliares()
        txtTitularID.Text = 0
        txtFamiliarID.Text = 0
        'txtCargoPuestoID.Text = ds.TB_SOC_ESI_CargoPuesto_ID
        '  txtEmpresaID.Text = ds.TB_SOC_ESI_Empresa_ID
        txtPersonaID.Text = 0
        txtCodPersona.Text = 0
        cmbFechaNacimiento.Value = Convert.ToDateTime(Now())
        cmbParentesco.Value = 1
        txtNombres.Text = ""
        txtApellidoPaterno.Text = ""
        txtApellidoMaterno.Text = ""
        txtIngresoMensual.Value = 0
        cmbTipoDocumento.Value = "DNI"
        txtNumeroDocumento.Text = ""

        cmbSexo.Value = "Hombre"
    End Sub

    Private Sub GrabaFichaFamiliar()
        Dim objFichaFamiliar As New BusinessLogic.crFichaFamiliar
        Dim ds As New BusinessEntity.CCFamiliar
        Dim objBase As New BusinessLogic.crConsulta
        ' Dim fichaID As String

        Try


            ds.TB_SOC_ESI_Familiar_ID = txtFamiliarID.Text
            ds.TB_SOC_ESI_Parentesco_ID = cmbParentesco.Value
            ds.TB_SOC_ESI_Titular_ID = DBUtilities.TitularID
            ds.TB_SOC_ESI_Persona_ID = txtPersonaID.Text
            'ds.TB_SOC_ESI_Persona_ID = Convert.ToInt32(objBase.Buscar_Campo(ds.TB_SOC_ESI_Titular_ID, "TB_SOC_ESI_Titular_ID", "TB_SOC_ESI_Persona_ID", "TB_SOC_ESI_Titular", "", "", ""))
            ds.CodPersona = txtCodPersona.Text
            'ds.AnioIngreso = "01/01/" + Convert.ToString(cmbAnioIngreso.Value)

            ds.Nombres = txtNombres.Text
            ds.ApellidoPaterno = txtApellidoPaterno.Text
            ds.ApellidoMaterno = txtApellidoMaterno.Text
            ds.FechaNacimiento = cmbFechaNacimiento.Value
            ds.TipoDocumento = cmbTipoDocumento.Value
            ds.NroDocumento = txtNumeroDocumento.Text
            ds.Sexo = cmbSexo.Value
            ds.IngresoMensual = txtIngresoMensual.Value 'Convert.ToInt32(txtIngresoMensual.Number)

            If objFichaFamiliar.GrabarFichaFamiliar(ds) Then
                lblMensaje.Visible = True
                lblMensaje.Text = "Grabo..."
               
                If DBUtilities.Formulario = "T" Then
                    Response.Redirect("~/Pages/frmGestionarSocio.aspx?KEY=" + Convert.ToString(DBUtilities.TitularID))
                ElseIf DBUtilities.Formulario = "I" Then
                    Response.Redirect("~/Pages/frmDetalleFicha.aspx?KEY=" + Convert.ToString(DBUtilities.FichaIncripcionID))


                End If

            Else
                lblMensaje.Visible = True
                lblMensaje.Text = "No Grabo"
            End If


        Catch ex As System.IO.FileNotFoundException
            lblMensaje.Visible = True
            lblMensaje.Text = "No Grabo" 'ex.Message


        Catch ex As Exception

            lblMensaje.Visible = True
            lblMensaje.Text = "No Grabo" 'ex.Message

        End Try
    End Sub

    Public Sub SetPermissionForEdit(ByVal objRow As GridViewRow)
        CType(Me.FindControl("btnGrabar"), Button).Enabled = False

    End Sub

    Public Sub EnabledControls()
        'If bEnabled = False Then
        'Me.cmbTipoDocumento.Enabled = bEnabled
        'Me.cmbFechaInscripcion.Enabled = bEnabled

        'End If

    End Sub
    Public Sub CerrarPantalla()
        Response.Write("<script language='javascript'> { window.close();}</script>")
        Me.Dispose()
    End Sub

End Class
